package com.love.rongcommon.exception;

import cn.hutool.core.util.ObjectUtil;

public interface Assert {

    /**
     * 创建异常
     * @return 异常信息
     */
    BusinessException newBusinessException();

    default void isThrow() {
        throw newBusinessException();
    }

    default void isNull(Object o) {
        if (ObjectUtil.isNotNull(o)) {
            throw newBusinessException();
        }
    }

    default void isNotNull(Object o) {
        if (ObjectUtil.isNull(o)) {
            throw newBusinessException();
        }
    }

    default void isEmpty(Object o) {
        if (ObjectUtil.isNotEmpty(o)) {
            throw newBusinessException();
        }
    }

    default void isNotEmpty(Object o) {
        if (ObjectUtil.isEmpty(o)) {
            throw newBusinessException();
        }
    }

    default void isTrue(boolean o) {
        if (!o) {
            throw newBusinessException();
        }
    }

    default void isFalse(boolean o) {
        if (o) {
            throw newBusinessException();
        }
    }

    default void isEqual(Object obj, Object o) {
        if (!ObjectUtil.equals(obj, o)) {
            throw newBusinessException();
        }
    }

    default void isNotEqual(Object obj, Object o) {
        if (ObjectUtil.equals(obj, o)) {
            throw newBusinessException();
        }
    }

    default void isContains(Object obj, Object element) {
        if (!ObjectUtil.contains(obj, element)) {
            throw newBusinessException();
        }
    }

}
